/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

/**
 *
 * @author rafael
 */

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import domain.*;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author rafael
 */

@Repository
@Transactional


public class ClienteDao{

    @PersistenceContext
    private EntityManager em;

    public Clientes save(Clientes clientes) throws DataAccessException{        
        return em.merge(clientes);
    }

    public void delete(Clientes clientes) throws DataAccessException{
        em.remove(em.merge(clientes));
    }

    public Clientes load(Integer id) throws DataAccessException{
        return em.find(Clientes.class, id);
    }

    public List listAll() throws DataAccessException{        
        List<Clientes> result = em.createQuery("SELECT c FROM Clientes c").getResultList();
        return result;
    }

    


}
